package com.unknowpupil.web.controller;

import com.unknowpupil.web.base.Result;
import com.unknowpupil.web.component.qrzt.job.JobUtil;
import com.unknowpupil.web.component.wallet.service.CoinToolsService;
import com.unknowpupil.web.exception.MxException;
import com.unknowpupil.web.service.IAccountInfoService;
import com.unknowpupil.web.service.IAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


/**
 * @Classname: AppController
 * @Author: <a> w10g </a>
 * @CreateDate: Create in 2019/11/7 9:11
 * @Description:
 * @Version: 1.0
 */
@Api(description = "钱包调度接口")
@RestController
@RequestMapping(value = "/api/user")
public class AppController {

    @Autowired
    private IAccountInfoService accountInfoService;
    @Autowired
    private IAccountService accountService;
    private static final Logger logger = LoggerFactory.getLogger(AppController.class);

    @ApiOperation(value = "创建钱包", notes = "创建钱包接口")
    @PostMapping(value = "/create/wallet")
    public Result createWallet(@RequestParam(value = "userName") String userName,
                                       @RequestParam(value = "password") String password,
                                       @RequestParam(value = "invitationCode", required = false) String invitationCode) {
        return accountService.createWallet(userName, password, invitationCode);
    }


    @ApiOperation(value = "根据资源获取密钥", notes = "根据资源获取密钥接口")
    @PostMapping(value = "/find/secret/key")
    public Result createWallet(@RequestParam(value = "source") String source,
                               @RequestParam(value = "password") String password) throws MxException {
        return accountService.findSecretKeyBySource(password, source);
    }

    @ApiOperation(value = "获取用户信息", notes = "获取用户信息接口")
    @PostMapping(value = "/get/info")
    public Result getAccount(@RequestParam(value = "id") String id) throws MxException {
        return accountService.getAccount(id);
    }

    @ApiOperation(value = "获取用户资源信息", notes = "获取用户资源信息接口")
    @PostMapping(value = "/get/source")
    public Result getAccountInfo(@RequestParam(value = "id") String id) throws MxException {
        return accountInfoService.getAccountInfo(id);
    }

}
